import Mock from 'mockjs'

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: i,
    date: '2016-05-07',
    name: '王小虎',
    province: '上海',
    city: '普陀区',
    address: '上海市普陀区金沙江路 1518 弄'
  }))
}
const tHeader = ['ID', '时间', '姓名', '地区', '城市', '地址']
const tHeader_show = ['ID', '时间', '姓名', '地区']
const tHeader_noShow = ['城市', '地址']
export default [
  {
    url: '/vue3-admin-template/table/list',
    method: 'get',
    response: (config) => {
      const { type, title, page = 1, size = 20, sort } = config.query

      let mockList = List.filter(item => {
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < size * page && index >= size * (page - 1))

      return {
        code: 20000,
        data: {
          total: List.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/vue-element-admin/table/header',
    type: 'get',
    response: config => {
      return {
        code: 20000,
        data: tHeader_show
      }
    }
  },
  {
    url: '/vue-element-admin/table/id',
    type: 'get',
    response: config => {
      return {
        code: 20000,
        data: {
          noShowList: tHeader_noShow,
          showList: tHeader_show,
          list: tHeader
        }
      }
    }
  },
]
